package org.rednebula.framework.core;

import java.io.Serializable;

import org.rednebula.framework.core.context.ProcedureContext;
import org.rednebula.framework.core.exception.LandException;






public abstract class AbstractEnvironmentImpl implements IEnvironment,
		Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2128241393852161811L;

	static ThreadLocal<AbstractEnvironmentImpl> currentEnvironment = new ThreadLocal<AbstractEnvironmentImpl>();

	ProcedureEngine engine;

	public ProcedureEngine getEngine() {
		return engine;
	}

	public void setEngine(ProcedureEngine engine) {
		this.engine = engine;
		this.setContext(new ProcedureContext(engine));
	}
	public abstract <T> T lookup(String key);

	@Deprecated
	public abstract <T> T lookup(Class<T> type);

	@Deprecated
	public abstract <T> T get(Class<T> type, String[] searchOrder);

	public static synchronized void setEnvironment(
			AbstractEnvironmentImpl environment) {
		currentEnvironment.set(environment);
	}

	public static synchronized AbstractEnvironmentImpl popEnvironment() {
		AbstractEnvironmentImpl envi = getCurrent();
		setEnvironment(null);
		return envi;
	}

	public static AbstractEnvironmentImpl getCurrent() {
		return currentEnvironment.get();
	}

	public abstract IContext getContext(String contextName);

	public abstract void setContext(IContext context);

	public abstract IContext removeContext(IContext context);

	public abstract IContext removeContext(String contextName);

	public abstract Object get(String name, String[] searchOrder);

	public abstract Object get(String name, String[] searchOrder,
			boolean nullAllowed) throws LandException;

	public abstract Object get(String name, boolean nullAllowed)
			throws LandException;

	public abstract ClassLoader getClassLoader();

	public abstract void close();
}
